﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:Controls="clr-namespace:Sentinel.Support.Wpf"
             xmlns:Converters="clr-namespace:Sentinel.Support.Converters"
             xmlns:Windows="clr-namespace:Sentinel.Controls"
             mc:Ignorable="d"
             x:Class="Sentinel.Views.Gui.LogMessagesControl"
             x:Name="UserControl"
             d:DesignWidth="276.307"
             d:DesignHeight="34.038">

    <UserControl.Resources>
        <Converters:TypeToSmallImageConverter x:Key="TypeToImageConverter" />
        <Converters:BooleanToWidthConverter x:Key="BooleanToWidthConverter" />
        <Converters:MessageHasExceptionMetadataConverter x:Key="MessageHasExceptionMetadata" />
        <Converters:MetaDataConverter x:Key="MetaDataConverter" />
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment"
                    Value="Stretch" />
        </Style>
        <Converters:TimePreferenceConverter x:Key="TimePreferenceConverter" />
        <Converters:DatePreferenceConverter x:Key="DatePreferenceConverter" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <ListView x:Name="messages"
                  Grid.Column="0"
                  ItemsSource="{Binding Messages}">
            <ListView.View>
                <GridView>
                    <Controls:FixedWidthColumn Header="Type">
                        <Controls:FixedWidthColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image x:Name="icon"
                                           Width="16"
                                           Height="16"
                                           RenderOptions.BitmapScalingMode="NearestNeighbor"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"
                                           Source="{Binding Type, Converter={StaticResource TypeToImageConverter}}"
                                           Visibility="Collapsed" />
                                    <TextBlock x:Name="text"
                                               Text="{Binding Type}"
                                               Visibility="Collapsed" />
                                </StackPanel>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Preferences.SelectedTypeOption, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}}"
                                                 Value="1">
                                        <Setter TargetName="icon"
                                                Property="Visibility"
                                                Value="Visible" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Preferences.SelectedTypeOption, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}}"
                                                 Value="2">
                                        <Setter TargetName="text"
                                                Property="Visibility"
                                                Value="Visible" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Preferences.SelectedTypeOption, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}}"
                                                 Value="3">
                                        <Setter TargetName="icon"
                                                Property="Visibility"
                                                Value="Visible" />
                                        <Setter TargetName="text"
                                                Property="Visibility"
                                                Value="Visible" />
                                        <Setter TargetName="text"
                                                Property="Margin"
                                                Value="5,0,0,0" />
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </Controls:FixedWidthColumn.CellTemplate>
                    </Controls:FixedWidthColumn>
                    <GridViewColumn Header="Date" x:Name="DateColumn"/>
                    <GridViewColumn Header="Time" x:Name="TimeColumn"/>
                    <Controls:FixedWidthColumn Header="Thread"
                                               FixedWidth="{Binding Preferences.ShowThreadColumn, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}, Converter={StaticResource BooleanToWidthConverter}, ConverterParameter=50}"
                                               DisplayMemberBinding="{Binding Thread}" />
                    <GridViewColumn Header="Host"
                                    Width="{Binding Preferences.ShowSourceColumn, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}, Converter={StaticResource BooleanToWidthConverter}, ConverterParameter=100}"
                                    DisplayMemberBinding="{Binding MetaData, Converter={StaticResource MetaDataConverter}, ConverterParameter='Host'}" />
                    <GridViewColumn Header="System"
                                    DisplayMemberBinding="{Binding System}" />
                    <Controls:FixedWidthColumn FixedWidth="{Binding Preferences.ShowExceptionColumn, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}, Converter={StaticResource BooleanToWidthConverter}, ConverterParameter=30}">
                        <Controls:FixedWidthColumn.Header>
                            <Image Width="12"
                                   Height="12"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   RenderOptions.BitmapScalingMode="HighQuality"
                                   Source="../../Resources/Small/MonoLightning.png" />
                        </Controls:FixedWidthColumn.Header>
                        <Controls:FixedWidthColumn.CellTemplate>
                            <DataTemplate>
                                <Image x:Name="icon"
                                       Width="16"
                                       Height="16"
                                       RenderOptions.BitmapScalingMode="NearestNeighbor"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       Source="../../Resources/Small/Exception.png"
                                       Visibility="Hidden" />
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Converter={StaticResource MessageHasExceptionMetadata}}"
                                                 Value="true">
                                        <Setter TargetName="icon"
                                                Property="Visibility"
                                                Value="Visible" />
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </Controls:FixedWidthColumn.CellTemplate>
                    </Controls:FixedWidthColumn>
                    <GridViewColumn Header="Description"
                                    DisplayMemberBinding="{Binding Description}" />
                    <GridViewColumn Header="Source File"
                                    Width="{Binding Preferences.ShowSourceInformationColumns, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}, Converter={StaticResource BooleanToWidthConverter}, ConverterParameter=130}"
                                    DisplayMemberBinding="{Binding MetaData, Converter={StaticResource MetaDataConverter}, ConverterParameter='SourceFile'}" />
                    <GridViewColumn Width="{Binding Preferences.ShowSourceInformationColumns, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}, Converter={StaticResource BooleanToWidthConverter}, ConverterParameter=30}"
                                    Header="Line"
                                    DisplayMemberBinding="{Binding MetaData, Converter={StaticResource MetaDataConverter}, ConverterParameter='SourceLine'}" />
                    <GridViewColumn Width="{Binding Preferences.ShowSourceInformationColumns, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}, Converter={StaticResource BooleanToWidthConverter}, ConverterParameter=130}"
                                    Header="Class"
                                    DisplayMemberBinding="{Binding MetaData, Converter={StaticResource MetaDataConverter}, ConverterParameter='ClassName'}" />
                    <GridViewColumn Width="{Binding Preferences.ShowSourceInformationColumns, RelativeSource={RelativeSource AncestorType={x:Type Windows:MainWindow}, Mode=FindAncestor}, Converter={StaticResource BooleanToWidthConverter}, ConverterParameter=130}"
                                    Header="Method"
                                    DisplayMemberBinding="{Binding MetaData, Converter={StaticResource MetaDataConverter}, ConverterParameter='MethodName'}" />
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</UserControl>